//
//  MineController.m
//  BCNADemo
//
//  Created by 马东朝 on 2018/5/16.
//  Copyright © 2018年 马东朝. All rights reserved.
//

#import "MineController.h"
#define CellInd @"cell"
@interface MineController ()<UITableViewDelegate, UITableViewDataSource, SeleceLanaugeControllerDelegate>
{
    UIImageView *logoView;
    UILabel *accountLabel;
    UILabel *dueTimeLabel;
    UITableView *tableView;
    
    NSArray *iconArray;
}
@property (nonatomic, assign) NSString *lanauge;
@end

@implementation MineController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [tableView reloadData];
    self.tabBarController.tabBar.hidden = NO;
    [self.navigationController setNavigationBarHidden:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithHexString:@"#12121f"];
    self.titleLabel.text = @"GOLINK";
    self.but.hidden = YES;
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    
    //去掉透明后导航栏下边的黑边
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    [self.navigationController setNavigationBarHidden:NO];
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, kWidth(70), kWidth(70));
    [rightBtn setImage:[UIImage imageNamed:@"message@3x.png"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(handleRight) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"message@3x.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(handleRight)];
    
    
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    
    
    
    [self addLogoView];
    [self addLabels];
    [self addtableView];
    if ([lanagueStyle isEqualToString:@"English"]) {
      self.lanauge = @"English";
    }else{
    self.lanauge = @"简体中文";
    }
}
- (void)handleRight{
    //消息");
    
    
    
    [self getHtml5VCWithURL:@"/notice"];
    
}
- (void)addLogoView{
    logoView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWidth(250), kWidth(250))];
    logoView.center = CGPointMake(ScreenWidth/2, kHeight(230) + kWidth(250)/2);
    [self.view addSubview:logoView];
    logoView.image = [UIImage imageNamed:@"mineLOGO@3x.png"];
}
- (void)addLabels{
    accountLabel  = [[UILabel alloc] initWithFrame:CGRectMake(kWidth(30), CGRectGetMaxY(logoView.frame) + kHeight(50), ScreenWidth-kWidth(60), kHeight(60))];
    accountLabel.font = [UIFont systemFontOfSize:kHeight(56)];
    accountLabel.textAlignment = NSTextAlignmentCenter;
    accountLabel.textColor = [UIColor colorWithHexString:@"#ffffff"];
    [self.view addSubview:accountLabel];
    NSMutableString *accStr = [NSMutableString stringWithCapacity:0];
    NSString *loginStyle = [[NSUserDefaults standardUserDefaults] valueForKey:isLogInEmail];
    
    if ([loginStyle isEqualToString:[NSString enCryptKey:postKey strPassword:@"1"]]) {
        accStr = [[NSUserDefaults standardUserDefaults] valueForKey:EmailAdd];
    }else{
        accStr = [[NSUserDefaults standardUserDefaults] valueForKey:PhoneNum];
    }
    accountLabel.text = accStr;
    
    dueTimeLabel  = [[UILabel alloc] initWithFrame:CGRectMake(kWidth(30), CGRectGetMaxY(accountLabel.frame) + kHeight(30), ScreenWidth-kWidth(60), kHeight(45))];
    dueTimeLabel.font = [UIFont systemFontOfSize:kHeight(40)];
    dueTimeLabel.textAlignment = NSTextAlignmentCenter;
    dueTimeLabel.textColor = [UIColor colorWithHexString:@"#9194a6"];
    [self.view addSubview:dueTimeLabel];
    dueTimeLabel.text = StringWithKey(@"MineVC7");
    
    
    
}
- (void)addtableView{
    
    iconArray = @[@"usermess@3x.png", @"help@3x.png", @"abuoutUs@3x.png", @"lanauge@3x.png"];
    tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(dueTimeLabel.frame) + kHeight(320)/2, ScreenWidth, kHeight(180) * 4) style:UITableViewStylePlain];
    tableView.scrollEnabled = NO;
    tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:tableView];
    tableView.delegate = self;
    tableView.dataSource = self;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellInd];
    tableView.rowHeight = kHeight(180);
    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
}
#pragma mark -- UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
   UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellInd];
   cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.backgroundColor = [UIColor clearColor];
    cell.imageView.image = [UIImage imageNamed:iconArray[indexPath.row]];
    NSString *strkey = [NSString stringWithFormat:@"MineVC%ld", indexPath.row+1];
    cell.textLabel.text = StringWithKey(strkey);
    cell.textLabel.font = [UIFont systemFontOfSize:kHeight(52)];
    cell.textLabel.textColor = [UIColor colorWithHexString:@"#ffffff"];
    cell.detailTextLabel.textColor = [UIColor colorWithHexString:@"#9194a6"];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:kHeight(42)];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row == 3) {
        cell.detailTextLabel.text = self.lanauge;
    }
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    self.tabBarController.tabBar.hidden = YES;
    switch (indexPath.row) {
        case 0:
            {
                [self.navigationController pushViewController:[[AccountInfoController alloc]init] animated:YES];
            }
            break;
            
        case 1:
        {
            //
            [self getHtml5VCWithURL:@"/help"];
        }
            break;
        case 2:
        {
             [self.navigationController pushViewController:[[AboutUsController alloc]init] animated:YES];
        }
            break;
        case 3:
        {
            SeleceLanaugeController *seleVC = [[SeleceLanaugeController alloc]init];
            seleVC.delegate = self;
            [self.navigationController pushViewController:seleVC animated:YES];
        }
            break;
            
        default:
            break;
    }
}
#pragma mark -- SeleceLanaugeControllerDelegate
- (void)selectLanaugeWIthIndex:(NSInteger)index{
    NSArray *titArray = @[@"简体中文", @"English"];
    self.lanauge = titArray[index];
    [tableView reloadData];
    dueTimeLabel.text = StringWithKey(@"MineVC7");
    self.title = StringWithKey(@"RootVC1");
    RootController *rootVC = (RootController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    HomePageController *honeVC = (HomePageController *)rootVC.viewControllers.firstObject;
    honeVC.tabBarItem.title = StringWithKey(@"RootVC0");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)getHtml5VCWithURL:(NSString *)URL{
    NSLog(@"%@", [NSString stringWithFormat:@"%@%@", UrlAddress, URL]);
    WebViewController *webVC = [[WebViewController alloc] init];
    webVC.url =[NSString stringWithFormat:@"%@%@", UrlAddress, URL];
    [self.navigationController pushViewController:webVC animated:YES];
//    [GLHttpTool postWITHJSON:[NSString stringWithFormat:@"%@%@", UrlAddress, URL] params:nil success:^(id responseObj) {
//        NSLog(@"responseObj==%@", responseObj);
//
//    } failure:^(NSError *error) {
//        NSLog(@"error==%@", error);
//    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
